﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Visitor_SendFeedback : System.Web.UI.Page
{
    string user;
    SqlConnection cnn;

    protected void Page_Load(object sender, EventArgs e)
    {
        lblDateSend.Text = DateTime.Now.ToShortDateString();

        if (Session["Username"] == null)
        {
            Response.Redirect("LoginFail.aspx");
        }

        user = Session["Username"].ToString();
        cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["OPOConnectionString"].ToString());
        cnn.Open();
    }

    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Convert.ToString(Session["Username"]) == "")
        {

            this.Page.MasterPageFile = "~/MasterPage/Visitor.master";
        }
        else
        {
            this.Page.MasterPageFile = "~/MasterPage/VisitorAfterLogin.master";
        }
    }

    protected void imgbSend_Click(object sender, ImageClickEventArgs e)
    {
        SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["OPOConnectionString"].ToString());
        cnn.Open();
        SqlCommand cmd = new SqlCommand("Insert into Feedback (DateSent, Title, Content)"
                                        + "values (@DateSent, @Title, @Content)", cnn);

        cmd.Parameters.Add(new SqlParameter("@DateSent", SqlDbType.VarChar, 20));
        cmd.Parameters["@DateSent"].Value = lblDateSend.Text;
        cmd.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar, 100));
        cmd.Parameters["@Title"].Value = txtTitle.Text;
        cmd.Parameters.Add(new SqlParameter("@Content", SqlDbType.NVarChar, 1000));
        cmd.Parameters["@Content"].Value = txtContent.Text;
        cmd.ExecuteNonQuery();

        ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "ShowMessage()", true);
    }

    protected void imgbCancel_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("index.aspx");
    }
    
}